#include "messageeditarea.h"
#include<QVBoxLayout>
#include<QScrollBar>
#include"historymessagedialog.h"
MessageEditArea::MessageEditArea(QWidget*parent)
    :QWidget(parent)
{
    //设置必要的属性
    this->setFixedHeight(200);
    this->setStyleSheet("QWidget{background-color:rgb(190,190,190)}");
    this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
    //先创建一个垂直布局管理器，在向里面插入水平布局管理器
    QVBoxLayout* vlayout=new QVBoxLayout();
     vlayout->setSpacing(0);
    vlayout->setContentsMargins(0,0,0,0);
    this->setLayout(vlayout);

    //在垂直里面加上水平的布局管理器
    QHBoxLayout *hlayout=new QHBoxLayout();
    hlayout->setSpacing(0);
    hlayout->setContentsMargins(0,0,0,0);
    hlayout->setAlignment(Qt::AlignLeft|Qt::AlignTop);
    vlayout->addLayout(hlayout);
    //设置四个按钮
    QSize btnSize(35,35);
    QString style="QPushButton{background-color:rgb(245,245,245);border:none;}QPushButton:pressed{background-color:rgb(255,255,255)}";
    QSize iconSize(25,25);
    sendPixmapBtn=new QPushButton();
     sendPixmapBtn->setStyleSheet(style);
     sendPixmapBtn->setFixedSize(btnSize);
      sendPixmapBtn->setIcon(QIcon(":/resource/Image/sendpixmap.png"));
      sendPixmapBtn->setIconSize(iconSize);

       hlayout->addWidget(sendPixmapBtn);

      sendFileBtn=new QPushButton();
      sendFileBtn->setStyleSheet(style);
     sendFileBtn->setFixedSize(btnSize);
      sendFileBtn->setIcon(QIcon(":/resource/Image/sendfile.png"));
     sendFileBtn->setIconSize(iconSize);

      hlayout->addWidget(sendFileBtn);


      sendSoundBtn=new QPushButton();
       sendSoundBtn->setStyleSheet(style);
       sendSoundBtn->setFixedSize(btnSize);
       sendSoundBtn->setIcon(QIcon(":/resource/Image/sendsound.png"));
      sendSoundBtn->setIconSize(iconSize);

      hlayout->addWidget( sendSoundBtn);


      heistoryBtn=new QPushButton();
      heistoryBtn->setStyleSheet(style);
      heistoryBtn->setFixedSize(btnSize);
      heistoryBtn->setIcon(QIcon(":/resource/Image/heistory.png"));
      heistoryBtn->setIconSize(iconSize);

      hlayout->addWidget(heistoryBtn);
      //多行编辑框
      plainTextEdit=new QPlainTextEdit();
      QString editStyle=" QPlainTextEdit{background-color:transparent;border:none;padding:10px;font-size:14px}";
      plainTextEdit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
       plainTextEdit->setStyleSheet(editStyle);
      QString scollBarStyle="QScollBar:vertial{width:2px;background-color:rgb(45,45,45)}";
       plainTextEdit->verticalScrollBar()->setStyleSheet(scollBarStyle);
       vlayout->addWidget(plainTextEdit);
       //添加最后一个发送按钮
       sendTextBtn =new QPushButton();
        vlayout->addWidget(sendTextBtn,Qt::AlignRight);
       sendTextBtn->setFixedSize(120,40);
       sendTextBtn->setText("发送");
       QString sendTextStyle;
       sendTextStyle+="QPushButton{background-color:rgb(255,255,255);color:rgb(19,199,60)};QPushButton:hover{background-color:rgb(210,210,210)";
       sendTextStyle+="QPushButton:pressed{background-color:rgb(190,190,190)}";
       sendTextBtn->setStyleSheet(sendTextStyle);

}

void MessageEditArea::initSignalSlot()
{
    connect(heistoryBtn, &QPushButton::clicked, this, [=]() {

      HistoryMessageWidget* historyMessageWidget = new HistoryMessageWidget(this);
        historyMessageWidget->exec();
    });
}
